package com.icode.core.shared;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-1-4
 * Time: 上午11:31
 * To change this template use File | Settings | File Templates.
 */

public class ValidateNumHandle {

    private Map<String, Object> map = new HashMap<>();
    private static ValidateNumHandle validateNumHandle = new ValidateNumHandle();

    public static String sendValidateNum(String message, String phoneNum) {
        String strReg = "101100-WEB-HUAX-402801";   //注册号
        String strPwd = "RXYDMYPC";                 //密码
        String strSourceAdd = "";                   //子通道号，可为空（预留参数一般为空）
        String strPhone = phoneNum;         //手机号码，多个手机号用半角逗号分开，最多1000个
        String validateNum = createValidateNum();   //生成4位验证码
        String content = message.replaceAll("\\{0\\}", validateNum);
        String strContent = HttpSend.paraTo16(content);
        String strSmsUrl = "http://www.stongnet.com/sdkhttp/sendsms.aspx";
        String strSmsParam = "reg=" + strReg + "&pwd=" + strPwd + "&sourceadd=" + strSourceAdd + "&phone=" + strPhone + "&content=" + strContent;
        String strRes = HttpSend.postSend(strSmsUrl, strSmsParam);
        String nowTime = JodaTimeUtils.getTime("yyyy-MM-dd HH:mm:ss");
        validateNum = validateNum + nowTime;
        validateNumHandle.map.put(phoneNum, validateNum);
        return strRes;
    }

    public static String checkBalance() {
        String strReg = "101100-WEB-HUAX-402801";
        String strPwd = "RXYDMYPC";
        String strBalanceUrl = "http://www.stongnet.com/sdkhttp/getbalance.aspx";
        String strBalanceParam = "reg=" + strReg + "&pwd=" + strPwd;
        String strRes = HttpSend.postSend(strBalanceUrl, strBalanceParam);
        return strRes;
    }

    public static Map<String, Object> getValidateNum() {
        return validateNumHandle.map;
    }

    public static void removePhoneNum(String phoneNum) {
        validateNumHandle.map.remove(phoneNum);
    }

    private static String createValidateNum() {
        Random r = new Random();
        int number = r.nextInt(9000) + 1000;
        return number + "";
    }

    //客户
    public static String sendToCustomerOrService(String message, String phoneNum) {
        String strReg = "101100-WEB-HUAX-402801";
        String strPwd = "RXYDMYPC";
        String strSourceAdd = "";
        String strPhone = phoneNum;
        String content = message;
        String strContent = HttpSend.paraTo16(content);
        String strSmsUrl = "http://www.stongnet.com/sdkhttp/sendsms.aspx";
        String strSmsParam = "reg=" + strReg + "&pwd=" + strPwd + "&sourceadd=" + strSourceAdd + "&phone=" + strPhone + "&content=" + strContent;
        String strRes = HttpSend.postSend(strSmsUrl, strSmsParam);
        return strRes;
    }

    public static String sendLuckMsg(String name, String phoneNum, String prizeName) {
        String strReg = "101100-WEB-HUAX-402801";
        String strPwd = "RXYDMYPC";
        String strSourceAdd = "";
        String strPhone = phoneNum;
        String content = name + "您好，恭喜您提交的问卷调查荣获了" + prizeName + "，稍后我们的工作人员会联系您，请保持此电话畅通。【成都漫庭网】";
        String strContent = HttpSend.paraTo16(content);
        String strSmsUrl = "http://www.stongnet.com/sdkhttp/sendsms.aspx";
        String strSmsParam = "reg=" + strReg + "&pwd=" + strPwd + "&sourceadd=" + strSourceAdd + "&phone=" + strPhone + "&content=" + strContent;
        String strRes = HttpSend.postSend(strSmsUrl, strSmsParam);
        return strRes;
    }

    public static String sendToReserveUser(String name, String phoneNum, String houseInfoName, String startTime, String endTime) {
        String strReg = "101100-WEB-HUAX-402801";
        String strPwd = "RXYDMYPC";
        String strSourceAdd = "";
        String strPhone = phoneNum;
        String content = "尊敬的" + name + ":漫庭欢迎您回家！您预订的" + houseInfoName + startTime + "至" + endTime + "订单已提交，请提前安排好行程。稍后您的专属管家会联络您，详询400-831-3336。";
        String strContent = HttpSend.paraTo16(content);
        String strSmsUrl = "http://www.stongnet.com/sdkhttp/sendsms.aspx";
        String strSmsParam = "reg=" + strReg + "&pwd=" + strPwd + "&sourceadd=" + strSourceAdd + "&phone=" + strPhone + "&content=" + strContent;
        String strRes = HttpSend.postSend(strSmsUrl, strSmsParam);
        return strRes;
    }

    public static String sendToReserveManager(String name, String phoneNum, String userPhoneNum, String day, String night, String houseInfoName, String startTime, String endTime) {
        String strReg = "101100-WEB-HUAX-402801";
        String strPwd = "RXYDMYPC";
        String strSourceAdd = "";
        String strPhone = phoneNum;
        String content = "您有一个新的预订：" + name + "先生预订" + houseInfoName + startTime + "至" + endTime + "," + day + "间住" + night + "间夜" + ",联系方式" + userPhoneNum + "可以通过以下链接在手机上浏览http://***.com";
        String strContent = HttpSend.paraTo16(content);
        String strSmsUrl = "http://www.stongnet.com/sdkhttp/sendsms.aspx";
        String strSmsParam = "reg=" + strReg + "&pwd=" + strPwd + "&sourceadd=" + strSourceAdd + "&phone=" + strPhone + "&content=" + strContent;
        String strRes = HttpSend.postSend(strSmsUrl, strSmsParam);
        return strRes;
    }



}
